package com.anrongtec.zcpt.utils;

import com.anrongtec.zcpt.model.User;
import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
import com.google.gson.reflect.TypeToken;

import java.io.Serializable;
import java.lang.reflect.Type;

/**
 * 解析服务器json对象
 * @author cxy
 *
 */
public class JsonDataRestult<T> implements Serializable {
	public static final String SCCUESS="0000";
	/**返回码*/
	@Expose
	private String retCode = "";
	/**返回信息*/
	@Expose
	private String retMsg = "";
	/**具体业务数据*/
	@Expose
	private T data;
	
	public String getRetCode() {
		return retCode;
	}
	public void setRetCode(String retCode) {
		this.retCode = retCode;
	}
	public String getRetMsg() {
		return retMsg;
	}
	public void setRetMsg(String retMsg) {
		this.retMsg = retMsg;
	}
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
	
	/**
	 * 解析User
	 * @param json
	 * @return
	 */
	public static JsonDataRestult<User> decodeUser(String json){
		Gson gson = new Gson();  
	    Type jsonType = new TypeToken<JsonDataRestult<User>>() {  
	    }.getType();  
	    return gson.fromJson(json, jsonType); 
	}
}
